#!/usr/bin/python
# -*- coding: utf-8 -*-

# ESiPC
from esipc import ESiPCProperty

from mikan.view import *
from mikan.viewlet import *
from mikan.viewlet.mviewlet import *

# ------------------------------------------------------------
## MIKAN jQuery Mobile テンプレート XHTMLビュークラス
#
class MikanTitleTemplateXHTMLView(MikanTemplateXHTMLView):
	def set_page_title(self, title):
		self.title.nodevalue = title + " - " + self.request.sitetitle

	def get_page_title(self):
		return self.title.nodevalue

	def get_body(self):
		return self.FBody

	def __init__(self, r, style=None):
		super(MikanTitleTemplateXHTMLView, self).__init__(r)

		self.FBody = MikanBodyViewlet(self.html)
		self.body.onload = "mikan.page.load();"
		self.body.onunload ="mikan.page.unload();"

	def perform(self):
		return super(MikanTitleTemplateXHTMLView, self).perform()

	# ----------------------------------------------------
	## Property
	body = ESiPCProperty(get_body, None, None)
	pagetitle = ESiPCProperty(get_page_title, set_page_title, None)

# ------------------------------------------------------------
## MIKAN jQuery Mobile テンプレート XHTMLビュークラス
#
class MikanContentTemplateXHTMLView(MikanTitleTemplateXHTMLView):

	def set_page_title(self, title):
		super(MikanContentTemplateXHTMLView, self).set_page_title(title)
		self.headertitle.nodevalue = title

	def get_content_target(self):
		return self.contentcenter

	def get_content_table(self):
		return self.FContentTable

	def get_content_left(self):
		return self.FContentLeft

	def get_content_center(self):
		return self.FContentCenter

	def get_content_right(self):
		return self.FContentRight

	def get_header(self):
		return self.FHeader

	def get_header_home(self):
		return self.FHeaderHome

	def get_header_button(self):
		return self.FHeaderButton

	def get_header_buttons(self):
		return self.FHeaderButtons

	def get_headerbar(self):
		return self.FHeaderBar

	def get_menubar(self):
		return self.FMenuBar

	def get_menubar_menu(self):
		return self.FMenuBarMenu

	def get_menubar_menus(self):
		return self.FMenuBarMenus

	def get_header_title(self):
		return self.FHeaderTitle

	def get_header_banner(self):
		return self.FHeaderBanner

	def get_footer(self):
		return self.FFooter

	def __init__(self, r, style=None):
		super(MikanContentTemplateXHTMLView, self).__init__(r)

		self.FHeaderBar = MikanTableViewlet(self.body)
		self.FHeaderBar.clazz = "headerbar"
		tr = MikanTrViewlet(self.headerbar)
		self.FHeaderHome = MikanTdViewlet(tr)
		self.FHeaderHome.clazz = "header_home"
		self.FHeaderButton = MikanTdViewlet(tr)
		self.FHeaderButton.clazz = "header_button"

		self.FHeaderButtons = MikanHeaderButtonViewlet(self.headerbutton)

		self.FHeader = MikanTableViewlet(self.body)
		self.FHeader.clazz = "header"
		tr = MikanTrViewlet(self.header)
		self.FHeaderLogo = MikanTdViewlet(tr)
		self.FHeaderLogo.clazz = "header_logo"
		MikanHeaderLogoViewlet(self.FHeaderLogo)

		self.FHeaderTitle = MikanTdViewlet(tr)
		self.FHeaderTitle.clazz = "header_title"
		self.FHeaderBanner = MikanTdViewlet(tr)
		self.FHeaderBanner.clazz = "header_banner"

		self.FMenuBar = MikanTableViewlet(self.body)
		self.FMenuBar.clazz = "menubar"
		tr = MikanTrViewlet(self.menubar)
		self.FMenuBarMenu = MikanTdViewlet(tr)
		self.FMenuBarMenu.clazz = "menubar_menu"
		self.FMenuBarMenus = MikanMenuViewlet(self.FMenuBarMenu, [])

		self.FContentTable = MikanTableViewlet(self.body)
		self.FContentTable.clazz = "content"

		tr = MikanTrViewlet(self.contenttable)

		self.FContentLeft = MikanTdViewlet(tr)
		self.FContentLeft.clazz = "content_left"
		self.FContentCenter = MikanTdViewlet(tr)
		self.FContentCenter.clazz = "content_center"
		self.FContentRight = MikanTdViewlet(tr)
		self.FContentRight.clazz = "content_right"

		self.FFooter = MikanFootBarViewlet(self.body)
		self.FFooter.clazz = "footer"

	def perform(self):
		MikanHeaderHomeViewlet(self.headerhome)
#		MikanDivViewlet(self.headertitle, self.title.nodevalue).clazz = "title"
#		MikanDivViewlet(self.headertitle, self.request.sitedescription)

		return super(MikanContentTemplateXHTMLView, self).perform()

	# ----------------------------------------------------
	## Property
	contenttarget = ESiPCProperty(get_content_target, None, None)
	contenttable = ESiPCProperty(get_content_table, None, None)
	contentleft = ESiPCProperty(get_content_left, None, None)
	contentcenter = ESiPCProperty(get_content_center, None, None)
	contentright = ESiPCProperty(get_content_right, None, None)
	header = ESiPCProperty(get_header, None, None)
	headerhome = ESiPCProperty(get_header_home, None, None)
	headerbutton = ESiPCProperty(get_header_button, None, None)
	headerbuttons = ESiPCProperty(get_header_buttons, None, None)
	headerbar = ESiPCProperty(get_headerbar, None, None)
	menubar = ESiPCProperty(get_menubar, None, None)
	menubarmenu = ESiPCProperty(get_menubar_menu, None, None)
	menubarmenus = ESiPCProperty(get_menubar_menus, None, None)
	headertitle = ESiPCProperty(get_header_title, None, None)
	headerbanner = ESiPCProperty(get_header_banner, None, None)
	footer = ESiPCProperty(get_footer, None, None)
